package com.dao;

import com.bean.MenuUrl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Ming on 2016/9/26.
 */
@Service
public class MenuUrlDao {
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    //定义一个父类集合List,负责存储所有的父
    public Map<Long,MenuUrl> getFatherIdAndOther(){
        return sqlSessionTemplate.selectMap("com.mapper.MenuUrlMapper.getFatherIdAndOther","id");
    }
    public Map<Long,MenuUrl> getFatherIdAndOther_2(){
        return sqlSessionTemplate.selectMap("com.mapper.MenuUrlMapper.getFatherIdAndOther_2","id");
    }

    //定义一个子集合List,负责存储父下的所有子
    public List<MenuUrl> getFatherToSon(Long parentId){
        return sqlSessionTemplate.selectList("com.mapper.MenuUrlMapper.getFatherToSon",parentId);
    }
    //获取子菜单url的ID
    public List<Long> getSonId(String url){
        return sqlSessionTemplate.selectList("com.mapper.MenuUrlMapper.getSonId",url);
    }

    //获取所有子菜单url
    public List<MenuUrl> getSonAll(Integer level){
        return sqlSessionTemplate.selectList("com.mapper.MenuUrlMapper.getSonAll",level);
    }
    public List<MenuUrl> getSonAll_2(){
        return sqlSessionTemplate.selectList("com.mapper.MenuUrlMapper.getSonAll_2");
    }

    //获取所有菜单信息
    public List<MenuUrl> getAllMenuMsg(){
        return sqlSessionTemplate.selectList("com.mapper.MenuUrlMapper.getAllMenuMsg");
    }
    //删除菜单信息__根据id
    public void delMenuMsgById(Long id){
        sqlSessionTemplate.delete("com.mapper.MenuUrlMapper.delMenuMsgById",id);
    }

    //更新菜单信息----根据id
    public int updateMenuMsgById(MenuUrl menuUrl){
        return sqlSessionTemplate.update("com.mapper.MenuUrlMapper.updateMenuMsgById",menuUrl);
    }

    //增加菜单信息
    public int insertMenuMsg(MenuUrl menuUrl){
        return sqlSessionTemplate.insert("com.mapper.MenuUrlMapper.insertMenuMsg",menuUrl);
    }
    //查询指定菜单信息通过id
    public List<MenuUrl> getMenuMsgById(Long id){
        return sqlSessionTemplate.selectList("com.mapper.MenuUrlMapper.getMenuMsgById",id);
    }


}
